﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Sale_Model;
using Sale_Operation;
using Sale_Common;
namespace SaleSystem
{
    public partial class _Default : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Session.Abandon();
                if (Request.Cookies["SaleSystemLogin"] != null)
                {
                    this.tb_SUser_Name.Text = Request.Cookies[strRememberParaName].Value;
                    this.tb_Remember.Checked = true;
                }
                else
                    this.tb_Remember.Checked = false;
            }
        }

        protected void bn_OK_Click(object sender, EventArgs e)
        {
            SysUser user = new SysUser();
            user.SUser_Name = this.tb_SUser_Name.Text;
            user.SUser_Pwd = this.tb_SUser_Pwd.Text;
            SysUsersOp UserOp = new SysUsersOp();
            bool bl = UserOp.Login(user);
            if (bl)
            {
                HttpSession session = new HttpSession();
                session["CurrentUser"] = user;
                LinkService.InsertLog(ESysLogType.Operation, "用户[" + user.SUser_Name + "]登陆系统，登陆时间：[" + System.DateTime.Now.ToString("yyyy-MM-dd hh:mmss") + "]！", 0);
                if (tb_Remember.Checked)
                {
                    HttpCookie cook = new HttpCookie(strRememberParaName);
                    cook.Expires = System.DateTime.MaxValue;
                    cook.Value = this.tb_SUser_Name.Text;
                    Response.Cookies.Add(cook);
                }
                else
                {
                    Response.Cookies.Remove(strRememberParaName);
                }
                Response.Redirect("main.aspx");
            }
            else
                ExtAspNet.Alert.Show("用户名或密码错误！", ExtAspNet.MessageBoxIcon.Error);
            
        }
        public string strRememberParaName = "SaleSystemLogin";
    }
}
